home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ham Radio 2000
/
Ham Radio 2000.iso
/
ham2000
/
tcp_ip
/
os2
/
pmnos11s
/
lpc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-30
|
24KB
|
1,093 lines
/* LPC - Line Printer Spooler Control
* written by David Johnson (dave@cs.olemiss.edu)
*
* This code is in the public domain.
*
* Revision History:
*
* Revision 1.2 91/09/26 dave (from Hans-Juergen Knobloch)
* Changed promote_job() to only promote job higher than the current
* highest job instead of straight to 'A'
*
* Revision 1.1 91/09/19 dave
* Calls to lpq and lprm are now wrapped by a local function to add
* argument to tell them not to use a new session
*
* Revision 1.0 91/09/04 dave
* Initial Release
*
*/
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <dir.h>
#include "config.h"
#include "global.h"
#include "mbuf.h"
#include "session.h"
#include "cmdparse.h"
#include "proc.h"
#include "tty.h"
#include "iface.h"
#include "socket.h"
#include "commands.h"
#include "netuser.h"
#include "dirutil.h"
#include "lp.h"
#include "lpd.h"
/* in lpd.c */
extern char *extract_parms __ARGS((char *local_parms, int extra));
extern int is_lpd_active __ARGS((void));
extern int is_job_specified __ARGS((char *cf_name));
/* in lpdunsp.c */
extern void start_unspooler_task __ARGS((int s, void *queue, void *p));
/* in lpdsubr.c */
extern int clear_status_flag __ARGS((char *queue, int flag));
extern int get_job_count __ARGS((char *queue));
extern int get_job_list __ARGS((char *directory, struct job_entry **job_list));
extern char **get_queue_list __ARGS((void));
extern char *get_spool_dir __ARGS((char *queue));
extern int is_unspooler_active __ARGS((char *queue, char **job));
extern int kill_unspooler __ARGS((char *queue));
extern int read_status __ARGS((char *queue, unsigned int *flags, unsigned int *next_seq, char **message));
extern int set_status_flag __ARGS((char *queue, int flag));
extern int signal_queue __ARGS((char *queue));
/* in lpclient.c */
#ifdef LPCLIENTS
extern int dolpq __ARGS((int argc,char *argv[],void *p));
extern int dolprm __ARGS((int argc,char *argv[],void *p));
#endif
/* local functions */
#ifdef LPCLIENTS
static int l_dolpq __ARGS((int argc,char *argv[],void *p));
static int l_dolprm __ARGS((int argc,char *argv[],void *p));
#endif
static int doabort __ARGS((int argc,char *argv[],void *p));
static int doclean __ARGS((int argc,char *argv[],void *p));
static int docontinue __ARGS((int argc,char *argv[],void *p));
static int dodisable __ARGS((int argc,char *argv[],void *p));
static int dodown __ARGS((int argc,char *argv[],void *p));
static int doenable __ARGS((int argc,char *argv[],void *p));
static int dohelp __ARGS((int argc,char *argv[],void *p));
static int dokill __ARGS((int argc,char *argv[],void *p));
static int dolock __ARGS((int argc,char *argv[],void *p));
static int dolpd __ARGS((int argc,char *argv[],void *p));
static int doquit __ARGS((int argc,char *argv[],void *p));
static int dorestart __ARGS((int argc,char *argv[],void *p));
static int dostart __ARGS((int argc,char *argv[],void *p));
static int dostatus __ARGS((int argc,char *argv[],void *p));
static int dostop __ARGS((int argc,char *argv[],void *p));
static int dotopq __ARGS((int argc,char *argv[],void *p));
static int dounlock __ARGS((int argc,char *argv[],void *p));
static int doup __ARGS((int argc,char *argv[],void *p));
static int getline __ARGS((struct session *sp,char *prompt,char *buf,int n));
static struct cmds LPCcmds[] = {
"", donothing, 0, 0, NULLCHAR,
"?", dohelp, 0, 0, NULLCHAR,
"abort", doabort, 0, 2, "abort ( all | <queue> ) [<queue> ...]",
"clean", doclean, 0, 2, "clean ( all | <queue> ) [<queue> ...]",
"continue", docontinue, 0, 1, "continue <queue>",
"disable", dodisable, 0, 2, "disable ( all | <queue> ) [<queue> ...]",
"down", dodown, 0, 2, "down ( all | <queue> ) [<queue> ...] [<message>]",
"enable", doenable, 0, 2, "enable ( all | <queue> ) [<queue> ...]",
"help", dohelp, 0, 0, NULLCHAR,
"kill", dokill, 0, 2, "kill ( all | <queue> ) [<queue> ...]",
"lock", dolock, 0, 0, NULLCHAR,
"lpd", dolpd, 0, 0, NULLCHAR,
#ifdef LPCLIENTS
"lprm", l_dolprm, 0, 0, NULLCHAR,
"lpq", l_dolpq, 0, 0, NULLCHAR,
#endif
"quit", doquit, 0, 0, NULLCHAR,
"restart", dorestart, 0, 2, "restart ( all | <queue> ) [<queue> ...]",
"start", dostart, 0, 2, "start ( all | <queue> ) [<queue> ...]",
"status", dostatus, 0, 0, NULLCHAR,
"stop", dostop, 0, 2, "stop ( all | <queue> ) [<queue> ...]",
"topq", dotopq, 0, 2, "topq <queue> <job> [<job>...]",
"unlock", dounlock, 0, 0, NULLCHAR,
"up", doup, 0, 2, "up ( all | <queue> ) [<queue> ...]",
NULLCHAR, NULLFP, 0, 0, "Unknown command",
};
char *help_strings[] = {
"? is same as 'help'",
"abort ( all | <queue> ): kill off server and disable printing",
"clean ( all | <queue> ): kill off server and remove spooler files from queue",
"continue <queue>: continue a single-sheet job",
"disable ( all | <queue> ): disable queueing",
"down ( all | <queue> ) (<message>): take printer down with message",
"enable ( all | <queue> ): enable queuing",
"help [all] [<command>]: print command summary",
"kill ( all | <queue> ): kill off server and then restart printing",
"lock : lock out maintenance commands",
"lpd : check out lpd process",
#ifdef LPCLIENTS
"lpq <parms>: call lpq",
"lprm <parms>: call lprm",
#endif
"quit : terminate; return to NOS command mode",
"restart ( all | <queue> ): start a server",
"start ( all | <queue> ): enable printing and start server",
"status [<queue>]: print status",
"stop ( all | <queue> ): disable further printing",
"topq <queue> (user|jobnumber): move job to top of queue",
"unlock : allow maintenance command usage",
"up ( all | <queue> ): bring printer back into service",
NULLCHAR
};
static int Slpc = -1; /* not actually socket; used to allow only one */
/* lpc to be active at a time */
static int locked = 0;
static char passwd[11]; /* lock password */
/* Handle top-level LPC command */
int
dolpc(argc,argv,p)
int argc;
char *argv[];
void *p;
{
struct session *sp;
char *buf, **pr, **opr;
unsigned int flags, next_seq;
char *message;
if( Slpc != -1 ) {
/* Already running! */
tprintf( "LPC is already active\n" );
return 0;
}
Slpc = 1; /* running */
/* Allocate a session control block */
if((sp = newsession(argv[1],LPUTILS)) == NULLSESSION){
tprintf("Too many sessions\n");
return 1;
}
/* look for printers which are currently paused */
for( opr = pr = get_queue_list(); pr && *pr; ++pr ) {
read_status( *pr, &flags, &next_seq, &message );
if( flags & PAUSED )
tprintf( "Queue %s is paused\n", *pr );
free( *pr );
}
if( opr ) {
free( *pr ); /* null entry */
free( opr );
}
/* process commands */
buf = mallocw( LINELEN );
do {
getline( sp, "lpc> ", buf, LINELEN );
cmdparse( LPCcmds, buf, NULL );
} while( Slpc > 0 ); /* quit sets to 0 */
free( buf );
freesession( sp );
Slpc = -1; /* not running */
return 0;
}
#ifdef LPCLIENTS
static int
l_dolpq(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int i;
char **pargv, *strdup();
pargv = (char **)callocw(argc+1,sizeof(char *));
for(i=0;i<argc;i++)
pargv[i] = strdup(argv[i]);
pargv[argc] = "-c"; /* tell lpq to not allocate a session */
dolpq(argc+1,pargv,p);
for(i=0;i<argc;i++)
free( pargv[i] );
free( pargv );
return 0;
}
static int
l_dolprm(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int i;
char **pargv, *strdup();
pargv = (char **)callocw(argc+1,sizeof(char *));
for(i=0;i<argc;i++)
pargv[i] = strdup(argv[i]);
pargv[argc] = "-c"; /* tell lprm to not allocate a session */
dolprm(argc+1,pargv,p);
for(i=0;i<argc;i++)
free( pargv[i] );
free( pargv );
return 0;
}
#endif /* LPCLIENTS */
static int
doabort(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int index = 1;
char *queue, **pr, **opr;
if( locked )
return 0;
dostop( argc, argv, p );
if( strcmp( argv[1], "all" ) == 0 ) {
/* all printers */
for( opr = pr = get_queue_list(); pr && *pr; ++pr ) {
if( kill_unspooler( *pr ) > 0 )
tprintf( "%s: server killed\n", *pr );
free( *pr );
}
if( opr ) {
free( *pr ); /* null entry */
free( opr );
}
} else {
/* specific list of printers */
while( index < argc ) {
queue = argv[ index ];
if( kill_unspooler( queue ) > 0 )
tprintf( "%s: server killed\n", queue );
index++;
}
}
return 0;
}
static void
clean_directory(directory)
char *directory;
{
char *path;
struct ffblk file_info;
path = pathname( directory, "*.*" );
if( findfirst( path, &file_info, 0 ) == 0 ) {
free( path );
if( *(file_info.ff_name + 1) == 'F' ) {
switch( *file_info.ff_name ) {
case 'C':
case 'D':
path = pathname( directory, file_info.ff_name );
remove( path );
free( path );
tprintf( "removed %s\n", file_info.ff_name );
break;
}
}
while( findnext( &file_info ) == 0 ) {
if( *(file_info.ff_name + 1) == 'F' ) {
switch( *file_info.ff_name ) {
case 'C':
case 'D':
path = pathname( directory, file_info.ff_name );
remove( path );
free( path );
tprintf( "removed %s\n", file_info.ff_name );
break;
}
}
}
} else
free( path );
}
static int
doclean(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int index = 1;
char *queue, **pr, **opr;
char *sd;
if( locked )
return 0;
if( strcmp( argv[1], "all" ) == 0 ) {
/* all printers */
for( opr = pr = get_queue_list(); pr && *pr; ++pr ) {
if( (sd = get_spool_dir( *pr )) == NULL )
continue;
clear_status_flag( *pr, PRINT_ENABLED&PAUSED );
clean_directory( sd );
if( kill_unspooler( *pr ) > 0 )
tprintf( "%s: server killed\n", *pr );
set_status_flag( *pr, PRINT_ENABLED );
free( sd );
free( *pr );
}
if( opr ) {
free( *pr ); /* null entry */
free( opr );
}
} else {
/* specific list of printers */
while( index < argc ) {
queue = argv[ index ];
if( (sd = get_spool_dir( queue )) == NULL )
continue;
clear_status_flag( *pr, PRINT_ENABLED&PAUSED );
clean_directory( sd );
if( kill_unspooler( *pr ) > 0 )
tprintf( "%s: server killed\n", *pr );
set_status_flag( *pr, PRINT_ENABLED );
free( sd );
index++;
}
}
return 0;
}
static int
docontinue(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int index = 1;
char *queue;
/* specific list of printers */
while( index < argc ) {
queue = argv[ index ];
signal_queue( queue );
index++;
}
}
static int
dodisable(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int index = 1;
char *queue, **pr, **opr;
if( locked )
return 0;
if( strcmp( argv[1], "all" ) == 0 ) {
/* all printers */
for( opr = pr = get_queue_list(); pr && *pr; ++pr ) {
clear_status_flag( *pr, QUEUE_ENABLED );
free( *pr );
}
if( opr ) {
free( *pr ); /* null entry */
free( opr );
}
} else {
/* specific list of printers */
while( index < argc ) {
queue = argv[ index ];
clear_status_flag( queue, QUEUE_ENABLED );
index++;
}
}
}
static int
dodown(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int index = 1;
char *queue, **pr, **opr;
char *path, *sd;
char message[256];
FILE *fp;
if( locked )
return 0;
*message = NULL;
if( strcmp( argv[1], "all" ) == 0 ) {
/* all printers */
for( opr = pr = get_queue_list(); pr && *pr; ++pr )
clear_status_flag( *pr, QUEUE_ENABLED|PRINT_ENABLED );
/* save message */
index = 2;
while( index < argc ) {
strcat( message, argv[ index ] );
strcat( message, " " );
index++;
}
/* Now record status message in each queue status file */
for( pr = opr; pr && *pr; ++pr ) {
if( (sd = get_spool_dir( *pr )) == NULL )
break;
path = pathname( sd, D_STATUS );
if( (fp = fopen( path, "w" )) != NULL ) {
fputs( message, fp );
putc( '\n', fp );
fclose( fp );
}
free( path );
free( sd );
free( *pr );
}
if( opr ) {
free( *pr ); /* null entry */
free( opr );
}
} else {
/* specific list of printers */
while( index < argc ) {
queue = argv[ index ];
if( clear_status_flag( queue, QUEUE_ENABLED|PRINT_ENABLED ) < 0 ) {
/* queue not recognized; must be start of message */
while( index < argc ) {
strcat( message, argv[ index ] );
strcat( message, " " );
index++;
}
} else
index++;
}
/* Now record message in each queue status file */
index = 1;
while( index < argc ) {
queue = argv[ index ];
if( (sd = get_spool_dir( queue )) == NULL ) {
/* end of recognized queues; start of message */
break;
}
path = pathname( sd, D_STATUS );
if( (fp = fopen( path, "w" )) != NULL ) {
fputs( message, fp );
putc( '\n', fp );
fclose( fp );
}
free( path );
free( sd );
index++;
}
}
}
static int
doenable(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int index = 1;
char *queue, **pr, **opr;
if( locked )
return 0;
if( strcmp( argv[1], "all" ) == 0 ) {
/* all printers */
for( opr = pr = get_queue_list(); pr && *pr; ++pr ) {
set_status_flag( *pr, QUEUE_ENABLED );
free( *pr );
}
if( opr ) {
free( *pr ); /* null entry */
free( opr );
}
} else {
/* specific list of printers */
while( index < argc ) {
queue = argv[ index ];
set_status_flag( queue, QUEUE_ENABLED );
index++;
}
}
}
static int
dohelp(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int index = 0, command_length, line_count;
char **hp, *cp, *command, *tp, temp[16];
if( argc < 2 ) {
hp = help_strings;
line_count = 0;
while( *hp ) {
cp = *hp++;
tp = temp;
while( *cp != ' ' )
*tp++ = *cp++;
*tp = NULL;
tprintf( "%-15s", temp );
if( ++line_count > 4 ) {
tputc( '\n' );
line_count = 0;
} else
tputc( ' ' );
}
tputc( '\n' );
} else {
if( strcmp( argv[1], "all" ) == 0 ) {
/* all commands */
hp = help_strings;
while( *hp ) {
tputs( *hp++ );
tputc( '\n' );
}
} else {
/* specific list of commands */
while( ++index < argc ) {
command = argv[ index ];
command_length = strlen( command );
hp = help_strings;
while( *hp && strncmp( command, *hp, command_length ) != 0 )
++hp;
if( *hp ) {
tputs( *hp );
tputc( '\n' );
}
}
}
}
return 0;
}
static int
dokill(argc,argv,p)
int argc;
char *argv[];
void *p;
{
if( locked )
return 0;
doabort( argc, argv, p );
return( dostart( argc, argv, p ) );
}
static int
dolock(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int length;
if( locked )
return 0;
if( !is_lpd_active() )
tprintf( "Warning: LPD is not active\n" );
Current->ttystate.echo = 0; /* Echo OFF */
length = getline( Current, "Enter Password: ", passwd, 10 );
Current->ttystate.echo = 1; /* Echo ON */
tprintf( "\n\n" );
if( length > 0 ) {
locked = 1;
tprintf( "Restricted mode enabled\n" );
} else {
tprintf( "not locked\n" );
}
return 0;
}
static int
dolpd(argc,argv,p)
int argc;
char *argv[];
void *p;
{
if( is_lpd_active() )
tprintf( "Active LPD\n" );
else
tprintf( "LPD is not active\n" );
return 0;
}
static int
doquit(argc,argv,p)
int argc;
char *argv[];
void *p;
{
if( locked )
return 0;
Slpc = 0;
return 0;
}
static int
dorestart(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int index = 1;
char *queue, **pr, **opr, *printer;
if( locked )
return 0;
if( !is_lpd_active() ) {
tprintf( "LPD is not active\n" );
return 0;
}
if( strcmp( argv[1], "all" ) == 0 ) {
/* all printers */
for( opr = pr = get_queue_list(); pr && *pr; ++pr ) {
printer = strdup( *pr ); /* child will free */
newproc("LPDprint",2048,start_unspooler_task,0,(void *)printer,NULL,0);
free( *pr );
}
if( opr ) {
free( *pr ); /* null entry */
free( opr );
}
} else {
/* specific list of printers */
while( index < argc ) {
queue = argv[ index ];
printer = strdup( queue ); /* child will free */
newproc("LPDprint",2048,start_unspooler_task,0,(void *)printer,NULL,0);
index++;
}
}
}
static int
dostart(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int index = 1;
char *queue, **pr, **opr;
if( locked )
return 0;
if( strcmp( argv[1], "all" ) == 0 ) {
/* all printers */
for( opr = pr = get_queue_list(); pr && *pr; ++pr ) {
set_status_flag( *pr, PRINT_ENABLED );
free( *pr );
}
if( opr ) {
free( *pr ); /* null entry */
free( opr );
}
} else {
/* specific list of printers */
while( index < argc ) {
queue = argv[ index ];
set_status_flag( queue, PRINT_ENABLED );
index++;
}
}
return( dorestart( argc, argv, p ) );
}
static int
show_queue_status( queue )
char *queue;
{
#define QUEUE_STATUS(flags) ((flags) & QUEUE_ENABLED ? "enabled " : "disabled")
#define PRINT_STATUS(flags) ((flags) & PRINT_ENABLED ? "enabled " : "disabled")
int active;
unsigned int flags, next_seq;
int job_count;
char *message;
char *job;
/* tprintf( "show_queue_status( %s )\n", queue );
tflush(); */
if( read_status( queue, &flags, &next_seq, &message ) < 0 ) {
tprintf( "%-14s\n does not exist\n", queue );
} else {
active = is_unspooler_active( queue, &job );
job_count = get_job_count( queue );
tprintf( "%-16s%4d %-10s%s ", queue, job_count,
QUEUE_STATUS(flags), PRINT_STATUS(flags) );
if( active ) {
tprintf( "(unspooler " );
if( flags & PAUSED )
tprintf( "paused" );
else
tprintf( "active" );
if( job )
tprintf( ", job %s", job );
tprintf( ")\n" );
} else
tprintf( "(no unspooler)\n" );
tprintf( " %s\n", message );
}
}
static int
dostatus(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int index = 1;
char *queue, **pr, **opr;
tputs( "Queue Jobs Queueing Printing\n" );
if( argc < 2 ) { /* must want all printers */
for( opr = pr = get_queue_list(); pr && *pr; ++pr ) {
show_queue_status( *pr );
free( *pr );
}
if( opr ) {
free( *pr ); /* null entry */
free( opr );
}
} else {
while( index < argc ) {
queue = argv[ index ];
show_queue_status( queue );
index++;
}
}
return 0;
}
static int
dostop(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int index = 1;
char *queue, **pr, **opr;
if( locked )
return 0;
if( strcmp( argv[1], "all" ) == 0 ) {
/* all printers */
for( opr = pr = get_queue_list(); pr && *pr; ++pr ) {
clear_status_flag( *pr, PRINT_ENABLED );
free( *pr );
}
if( opr ) {
free( *pr ); /* null entry */
free( opr );
}
} else {
/* specific list of printers */
while( index < argc ) {
queue = argv[ index ];
clear_status_flag( queue, PRINT_ENABLED );
index++;
}
}
}
static int
dotopq(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int i, job, job_count, buffer_size, modified = 0;
char *sd, *buffer;
struct job_entry *job_list;
if( locked )
return 0;
tprintf( "%s:\n", argv[1] );
if( (sd = get_spool_dir( argv[1] )) == NULL )
return -1;
/*
* Figure out buffer size for extract_parms()
*/
buffer_size = 0;
for( i = 1; i < argc; i++ )
buffer_size += strlen( argv[ i ] ) + 1; /* plus space */
buffer = (char *)mallocw( buffer_size );
for( i = 1; i < argc; i++ ) {
strcat( buffer, argv[ i ] );
if( i+1 < argc )
strcat( buffer, " " );
}
(void)extract_parms( buffer, 1 );
free( buffer );
job_count = get_job_list( sd, &job_list );
for( job = 0; job < job_count; job++ ) {
if( !is_job_specified( job_list[ job ].j_name ) )
continue;
/*
* Promote job to top of queue
*/
if( promote_job( sd, job_list[ job ].j_name,
job_list[ 0 ].j_name[2] ) < 0 )
continue;
modified++;
free( job_list[ job ].j_name );
job_list[ job ].j_name = NULL;
}
/*
* Put other high priority jobs lower
*/
if( !modified ) {
for( job = 0; job < job_count; job++ ) {
if( job_list[ job ].j_name )
free( job_list[ job ].j_name );
}
free( job_list );
return 0;
}
for( job = 0; job < job_count; job++ ) {
if( job_list[ job ].j_name && job_list[ job ].j_name[2] == 'A' ) {
touch( sd, job_list[ job ].j_name );
free( job_list[ job ].j_name );
} else {
free( job_list[ job ].j_name );
}
}
free( job_list );
free( sd );
tprintf( "queue order changed\n" );
/*
* Force unspooler to rebuild the queue after current job
*/
set_status_flag( argv[1], FORCE_REQUE );
return 0;
}
static int
promote_job( directory, cf_name, prior )
char *directory, *cf_name, prior;
{
char buffer[16], *source_path, *dest_path;
strcpy( buffer, cf_name );
if( prior > 'A')
prior--;
buffer[ 2 ] = prior;
if( strcmp( buffer, cf_name ) == 0 )
return -1; /* already high priority */
source_path = pathname( directory, cf_name );
dest_path = pathname( directory, buffer );
if( rename( source_path, dest_path ) < 0 ) {
free( source_path );
free( dest_path );
return -1;
}
tprintf( "promoting %s to %s\n", cf_name, buffer );
free( source_path );
free( dest_path );
return 0;
}
static int
touch( directory, cf_name )
char *directory, *cf_name;
{
int c;
char *path;
FILE *fp;
path = pathname( directory, cf_name );
if( (fp = fopen( path, "rw" )) == NULL ) {
free( path );
return -1;
} else if( (c = getc( fp )) == EOF )
goto finish;
else if( fseek( fp, 0L, 0 ) < 0 )
goto finish;
else if( putc( c, fp ) == EOF )
goto finish;
else if( fflush( fp ) == EOF )
goto finish;
finish: if( fp != NULL )
fclose( fp );
free( path );
return 0;
}
static int
dounlock(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int length;
char lpasswd[11];
if( locked == 0 )
return 0;
if( !is_lpd_active() )
tprintf( "Warning: LPD is not active\n" );
Current->ttystate.echo = 0; /* Echo OFF */
length = getline( Current, "Enter Password: ", lpasswd, 10 );
Current->ttystate.echo = 1; /* Echo ON */
tprintf( "\n\n" );
if( length > 0 ) {
if( strcmp( passwd, lpasswd ) == 0 ) {
locked = 0;
tprintf( "Restricted mode canceled\n" );
} else
tprintf( "Invalid password.\n" );
} else {
tprintf( "Restricted mode\n" );
}
return 0;
}
static int
doup(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int index = 1;
char *queue, **pr, **opr;
char *path, *sd;
if( locked )
return 0;
if( strcmp( argv[1], "all" ) == 0 ) {
/* all printers */
for( opr = pr = get_queue_list(); pr && *pr; ++pr ) {
set_status_flag( *pr, QUEUE_ENABLED|PRINT_ENABLED );
/* delete status file */
if( (sd = get_spool_dir( *pr )) != NULL ) {
path = pathname( sd, D_STATUS );
remove( path );
free( path );
free( sd );
}
free( *pr );
}
if( opr ) {
free( *pr ); /* null entry */
free( opr );
}
} else {
/* specific list of printers */
while( index < argc ) {
queue = argv[ index ];
set_status_flag( queue, QUEUE_ENABLED|PRINT_ENABLED );
/* delete status file */
if( (sd = get_spool_dir( queue )) != NULL ) {
path = pathname( sd, D_STATUS );
remove( path );
free( path );
free( sd );
}
index++;
}
}
}
/* Issue a prompt and read a line from the user */
static int
getline(sp,prompt,buf,n)
struct session *sp;
char *prompt;
char *buf;
int n;
{
/* If there's something already there, don't issue prompt */
if(socklen(sp->input,0) == 0)
tprintf(prompt);
usflush(sp->output);
return recvline(sp->input,buf,n);
}